package com.guigu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guigu.mapper.EvaluateDetailMapper;
import com.guigu.pojo.EvaluateDetail;
import com.guigu.service.CommentOnCommodityService;
import com.guigu.service.EvaluateDetailService;
import com.guigu.service.ShopInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EvaluateDetailServiceImpl extends ServiceImpl<EvaluateDetailMapper, EvaluateDetail>
implements EvaluateDetailService {

    @Autowired
    CommentOnCommodityService commentService;
    @Autowired
    ShopInfoService shopService;

    @Override
    public Page<EvaluateDetail> queryPageEvaluates(EvaluateDetail evaluate, Integer pageno, Integer pagesize) {
        QueryWrapper<EvaluateDetail> queryWrapper=
                new QueryWrapper<EvaluateDetail>();
        if (evaluate.getGid()!=null){
            queryWrapper.eq("gid",evaluate.getGid());
        }
        Page<EvaluateDetail> page = this.page(new Page<EvaluateDetail>(pageno, pagesize), queryWrapper);
        for (EvaluateDetail record : page.getRecords()) {
            record.setComment(commentService.queryById(record.getPid()));
        }
        return page;
    }

    @Override
    public List<EvaluateDetail> queryEvaluatesByPid(Integer pid) {
        QueryWrapper<EvaluateDetail> queryWrapper=
                new QueryWrapper<EvaluateDetail>();
        if (pid!=null){
            queryWrapper.eq("pid",pid);
        }
        List<EvaluateDetail> list = this.list(queryWrapper);
        for (EvaluateDetail detail : list) {
            detail.setShopInfo(shopService.queryShopById(detail.getGid()));
        }
        return list;
    }
}
